
const UserModel = require("../../models/UserModel")

const UserService = {
    // req.body  解构{username,passsword}
    login: async ({ username, passsword }) => {
        return UserModel.find({ username, passsword })
    },
    uploadFile:async({_id,username,introduction,gender,avatar})=>{
       if(avatar){
        return UserModel.updateOne({_id},{
            username,introduction,gender,avatar
        })
       }else{
        return UserModel.updateOne({_id},{
            username,introduction,gender
        })
       }
    },
    addUser:({username,introduction,gender,avatar,role,password})=>{
        return UserModel.create({username,introduction,gender,avatar,role,password})
    },
    getUserList:()=>{
        return UserModel.find({},["username","introduction","gender","avatar","role"])
    },
    deleteUser:(obj)=>{
        return UserModel.deleteOne({_id:obj._id})
    }
}

module.exports = UserService